package arduino.handler;

import java.io.IOException;

import arduino.AProtocol;
import arduino.AServer;
import arduino.InternalCommunicationSerice;
import net.udp.server.RequestHandler;

public class ArduinoRequestHandler implements RequestHandler {

	InternalCommunicationSerice service = InternalCommunicationSerice.getInstance();
	@Override
	public String process(String request) throws IOException {
		AProtocol a = AProtocol.parse(request);
		
		service.setClient2server(a);
		delay(250l);
		a = service.getServer2client();
		if(a==null)
		{
			return null;
		}
		else
		{
			return a.toString();
		}
		
		
	}

	private void delay(long msec)
	{
		try {
			Thread.sleep(250l);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
